package peerToPeerFacebook.proj;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import peerToPeerFacebook.src.edu.washington.cs.cse490h.lib.Callback;
import peerToPeerFacebook.src.edu.washington.cs.cse490h.lib.Node;
import peerToPeerFacebook.src.edu.washington.cs.cse490h.lib.Packet;
import peerToPeerFacebook.src.edu.washington.cs.cse490h.lib.PersistentStorageWriter;
import peerToPeerFacebook.src.edu.washington.cs.cse490h.lib.Utility;

public class NodeWrapper implements INode, IStorageProvider
{
	protected Node self;
	
	public NodeWrapper(Node self)
	{
		this.self = self;
	}
	
	@Override
	public void send(int destAddr, int protocol, byte[] payload)
	{
		self.send(destAddr, protocol, payload);
	}

	@Override
	public void addTimeout(Callback cb, int timer)
	{
		self.addTimeout(cb, timer);
	}

	@Override
	public InputStream getInputStream(String filename)
			throws FileNotFoundException
	{
		return self.getInputStream(filename);
	}

	@Override
	public OutputStream getOutputStream(String filename,
			boolean append) throws IOException
	{
		return self.getOutputStream(filename, append);
	}

	@Override
	public void logSynopticEvent(String eventStr)
	{
		self.logSynopticEvent(eventStr);
	}

	@Override
	public int getAddr()
	{
		return self.addr;
	}

	@Override
	public int maxPacketSize()
	{
		return Packet.MAX_PAYLOAD_SIZE;
	}

	@Override
	public BufferedReader getReader(String name) throws IOException
	{
		return self.getReader(name);
	}

	@Override
	public BufferedWriter getWriter(String name, boolean append) throws IOException
	{
		return self.getWriter(name, append);
	}

	@Override
	public boolean fileExists(String name)
	{
		return Utility.fileExists(self, name);
	}

	@Override
	public boolean delete(String name) throws IOException
	{
		PersistentStorageWriter writer = self.getWriter(name, false);
		return writer.delete();		
	}
}
